import settings
from httpx import post, get


class BaseApi:
    def requests(self, method: str, url: str, data: dict = {}) -> dict:
        try:
            req_method = method.lower()
            if req_method == 'post':
                data["bk_token"] = settings.BK_TOKEN
                data["bk_app_code"] = settings.BK_APP_CODE
                data["bk_app_secret"] = settings.BK_APP_SECRET
                req = post(url="{0}{1}/".format(settings.CMDB_API_URL, url), json=data, verify=False)
                return req.json()
        except Exception as e:
            return {"result": False, "code": 0, "data": [], "message": e, "permission": e}
